home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kopete / kopetemetacontact.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-10-01  |  18.0 KB  |  616 lines

  1. /*
  2.     kopetemetacontact.h - Kopete Meta Contact
  3.  
  4.     Copyright (c) 2002-2003 by Martijn Klingens       <klingens@kde.org>
  5.     Copyright (c) 2002-2005 by Duncan Mac-Vicar Prett <duncan@kde.org>
  6.     Copyright (c) 2002-2005 by Olivier Goffart        <ogoffart @ kde.org>
  7.     Copyright (c) 2003      by Will Stephenson        <will@stevello.free-online.co.uk>
  8.  
  9.     Kopete    (c) 2002-2004 by the Kopete developers  <kopete-devel@kde.org>
  10.  
  11.     *************************************************************************
  12.     *                                                                       *
  13.     * This library is free software; you can redistribute it and/or         *
  14.     * modify it under the terms of the GNU Lesser General Public            *
  15.     * License as published by the Free Software Foundation; either          *
  16.     * version 2 of the License, or (at your option) any later version.      *
  17.     *                                                                       *
  18.     *************************************************************************
  19. */
  20.  
  21. #ifndef kopetemetacontact_h__
  22. #define kopetemetacontact_h__
  23.  
  24. #include "kopetecontactlistelement.h"
  25. #include <qptrlist.h>
  26. #include <qstring.h>
  27.  
  28. #include <kdemacros.h>
  29. #include "kopete_export.h"
  30.  
  31. #include "kopetenotifydataobject.h"
  32. #include "kopetecontactlistelement.h"
  33. #include "kopeteonlinestatus.h"
  34.  
  35. class QDomNode;
  36.  
  37. class KURL;
  38.  
  39. namespace Kopete {
  40.  
  41.  
  42. class Plugin;
  43. class Group;
  44. class Picture;
  45.  
  46. /**
  47.  * @author Will Stephenson <will@stevello.free-online.co.uk>
  48.  * @author Martijn Klingens <klingens@kde.org>
  49.  * @author Duncan Mac-Vicar Prett <duncan@kde.org>
  50.  * @author Olivier Goffart <ogoffart@tiscalinet.be>
  51.  *
  52.  * A metacontact represent a person. This is a kind of entry to
  53.  * the contactlist. All information of a contact is contained in
  54.  * the metacontact. Plugins can store data in it with all
  55.  * @ref ContactListElement methods
  56.  */
  57. class KOPETE_EXPORT MetaContact : public ContactListElement, public NotifyDataObject
  58. {
  59.     Q_OBJECT
  60.  
  61.     Q_PROPERTY( QString displayName READ displayName WRITE setDisplayName )
  62.     Q_PROPERTY( QString statusString READ statusString )
  63.     Q_PROPERTY( QString statusIcon READ statusIcon )
  64.     Q_PROPERTY( bool isOnline READ isOnline )
  65.     Q_PROPERTY( bool isReachable READ isReachable )
  66.     Q_PROPERTY( bool isTemporary READ isTemporary )
  67.     Q_PROPERTY( bool canAcceptFiles READ canAcceptFiles )
  68.     //Q_PROPERTY( ulong idleTime READ idleTime )
  69.     Q_PROPERTY( QString metaContactId READ metaContactId WRITE setMetaContactId )
  70.     Q_PROPERTY( bool photoSyncedWithKABC READ isPhotoSyncedWithKABC WRITE setPhotoSyncedWithKABC )
  71.  
  72. public:
  73.     /** 
  74.      * Enumeration of possible sources for a property (which may be
  75.      * photos, see setPhotoSource() for instance).
  76.      */
  77.     enum PropertySource { 
  78.         SourceContact /**< Data comes from the contact itself. */, 
  79.         SourceKABC /**< Data comes from KABC (addressbook). */, 
  80.         SourceCustom /**< Data comes from somewhere else. */
  81.     };
  82.  
  83.     /**
  84.      * constructor
  85.      */
  86.     MetaContact();
  87.     /**
  88.      * destructor
  89.      */
  90.     ~MetaContact();
  91.  
  92.     /**
  93.      * @brief Returns this metacontact's ID.
  94.      *
  95.      * Every metacontact has a unique id, set by  when creating the contact, or reading the contactlist
  96.      * TODO: make it real
  97.      */
  98.     QString metaContactId() const;
  99.  
  100.     /**
  101.      * @brief Add or change the link to a KDE addressbook (KABC) Addressee.
  102.      * FIXME: Use with care.  You could create 1 to many relationships with the current implementation
  103.      */
  104.     void setMetaContactId( const QString& newMetaContactId );
  105.  
  106.     /**
  107.      * @brief Retrieve the list of contacts that are part of the meta contact
  108.      */
  109.     QPtrList<Contact> contacts() const;
  110.  
  111.     /**
  112.      * @brief The groups the contact is stored in
  113.      */
  114.     QPtrList<Group> groups() const;
  115.  
  116.     /**
  117.      * Find the Contact to a given contact. If contact
  118.      * is not found, a null pointer is returned.
  119.      * if @p protocolId or @p accountId are null, it is searched over all protocols/accounts
  120.      */
  121.     Contact *findContact( const QString &protocolId, const QString &accountId, const QString &contactId );
  122.  
  123.     /**
  124.      * @brief Set the source of metacontact displayName
  125.      *
  126.      * This method selects the display name source for one
  127.      * of the sources defined in @ref PropertySource
  128.      *
  129.      * @see PropertySource
  130.      */
  131.     void setDisplayNameSource(PropertySource source);
  132.  
  133.     /**
  134.      * @brief get the source of metacontact display name
  135.      *
  136.      * This method obtains the current name source for one
  137.      * of the sources defined in @ref PropertySource
  138.      *
  139.      * @see PropertySource
  140.      */
  141.     PropertySource displayNameSource() const;
  142.  
  143.     /**
  144.      * @brief Set the source of metacontact photo
  145.      *
  146.      * This method selects the photo source for one
  147.      * of the sources defined in @ref PropertySource
  148.      *
  149.      * @see PropertySource
  150.      */
  151.     void setPhotoSource(PropertySource source);
  152.  
  153.     /**
  154.      * @brief get the source of metacontact photo
  155.      *
  156.      * This method obtains the current photo source for one
  157.      * of the sources defined in @ref PropertySource
  158.      *
  159.      * @see PropertySource
  160.      */
  161.     PropertySource photoSource() const;
  162.  
  163.     /**
  164.      * @brief the display name showed in the contactlist window
  165.      *
  166.      * The displayname is the name which should be shown almost everywere to
  167.      * represent the metacontact.  (in the contactlist, in the chatwindow, ....)
  168.      *
  169.      * This is a kind of alias, set by the kopete user, as opposed to a nickname
  170.      * set by the contact itself.
  171.      *
  172.      * If the protocol support alias serverside, the metacontact displayname
  173.      * should probably be syncronized with the alias on the server.
  174.      *
  175.      * This displayName is obtained from the source set with @ref setDisplayNameSource
  176.      */
  177.     QString displayName() const;
  178.  
  179.     /**
  180.      * @brief the photo showed in the contactlist window
  181.      *
  182.      * Returns a image for the metacontact. If the metacontact photo source is
  183.      * the KDE addressbook. it will return the picture stored in the addressbook
  184.      * It can also use a subcontact as the photo source.
  185.      *
  186.      * This photo is obtained from the source set with @ref setPhotoSource
  187.      */
  188.     QImage photo() const;
  189.  
  190.     /**
  191.      * Return the correct Kopete::Picture object depending of the metacontact photo source.
  192.      *
  193.      * This photo is obtained from the source set with @ref setPhotoSource
  194.      *
  195.      * KDE4 TODO: Rename this to photo() and use the new object.
  196.      */
  197.     Picture &picture() const;
  198.  
  199.     /**
  200.      * @brief Set the custom displayName.
  201.      *
  202.      * This display name is used when name source is Custom
  203.      * this metohd may emit @ref displayNameChanged signal.
  204.      * And will call @ref Kopete::Contact::sync
  205.      *
  206.      * @see displayName()
  207.      * @see displayNameSource()
  208.      */
  209.     void setDisplayName( const QString &name );
  210.  
  211.     /**
  212.      * @brief Returns the custom display name
  213.      *
  214.      * @see displayName()
  215.      * @see displayNameSource()
  216.      */
  217.     QString customDisplayName() const;
  218.  
  219.     /**
  220.      * @brief Returns the custom display photo
  221.      *
  222.      * @see photo()
  223.      * @see photoSource()
  224.      */
  225.     KURL customPhoto() const;
  226.  
  227.  
  228.     /**
  229.      * @brief Set the custom photo.
  230.      *
  231.      * This photo is used when photo source is set toCustom
  232.      * this metohd may emit @ref photoChanged signal.
  233.      *
  234.      * @see photo()
  235.      * @see photoSource()
  236.      */
  237.     void setPhoto( const KURL &url );
  238.  
  239.     /**
  240.      * @brief get the subcontact being tracked for its displayname (null if not set)
  241.      *
  242.      * The MetaContact will adjust its displayName() every time the
  243.      * "nameSource" changes its nickname property.
  244.      */
  245.     Contact *displayNameSourceContact() const;
  246.  
  247.     /**
  248.      * @brief set the subcontact whose name is to be tracked (set to null to disable tracking)
  249.      * @see nameSource
  250.      */
  251.     void setDisplayNameSourceContact( Contact* contact );
  252.  
  253.     /**
  254.      * @brief get the subcontact being tracked for its photo
  255.      */
  256.     Contact *photoSourceContact() const;
  257.  
  258.     /**
  259.      * @brief set the subcontact to use for SourceContact source
  260.      */
  261.     void setPhotoSourceContact( Contact* contact );
  262.  
  263.     /**
  264.      * @return true if when a subcontact change his photo, the photo will be set to the kabc contact.
  265.      */
  266.     bool isPhotoSyncedWithKABC() const;
  267.  
  268.     /**
  269.      * Set if the photo should be synced with the adressbook when the photosource change his photo
  270.      *
  271.      * If  \p b is true, the photo will be synced immediatly if possible
  272.      */
  273.     void setPhotoSyncedWithKABC(bool b);
  274.  
  275.  
  276.     /**
  277.      * Temporary contacts will not be serialized.
  278.      * If they are added to the contactlist, they appears in a special "Not in your contactlist" group.
  279.      * (the @ref Group::temporary  group)
  280.      */
  281.     bool isTemporary() const;
  282.  
  283.     /**
  284.      * @brief Add a contact which has just been deserialised to the meta contact
  285.      * @param c The Contact being added
  286.      */
  287.     void addContact( Contact *c );
  288.  
  289.     /**
  290.      * @brief remove the contact from this metacontact
  291.      *
  292.      * set 'deleted' to true if the Contact is already deleted
  293.      *
  294.      * @param c is the contact to remove
  295.      * @param deleted : if it is false, it will disconnect the old contact, and call some method.
  296.      */
  297.     void removeContact( Contact *c , bool deleted = false );
  298.  
  299.     /**
  300.      * @return the preferred child Contact for communication, or 0 if none is suitable (all unreachable).
  301.      */
  302.     Contact *preferredContact();
  303.  
  304.     /**
  305.      * @brief The name of the icon associated with the contact's status
  306.      * @todo improve with OnlineStatus
  307.      */
  308.     QString statusIcon() const;
  309.  
  310.     /**
  311.      * @brief The status string of the contact
  312.      *
  313.      * @see @ref status()
  314.      * @todo improve with OnlineStatus
  315.      */
  316.     QString statusString() const;
  317.  
  318.     /**
  319.      * Returns whether this contact can be reached online for at least one
  320.      * FIXME: Make that an enum, because status can be unknown for certain
  321.      *        protocols
  322.      */
  323.     bool isOnline() const;
  324.  
  325.     /**
  326.      * Returns whether this contact can accept files
  327.      * @return True if the user is online with a file capable protocol, false otherwise
  328.      */
  329.     bool canAcceptFiles() const;
  330.  
  331.     /**
  332.      * Return a more fine-grained status.
  333.      * Online means at least one sub-contact is online, away means at least
  334.      * one is away, but nobody is online and offline speaks for itself
  335.      */
  336.     OnlineStatus::StatusType status() const;
  337.  
  338.     /**
  339.      * Like isOnline, but returns true even if the contact is not online, but
  340.      * can be reached trough offline-messages.
  341.      * it it return false, you are unable to open a chatwindow
  342.      * @todo : Here too, use preference order, not append order!
  343.      * @todo : Here too an enum.
  344.      */
  345.     bool isReachable() const;
  346.  
  347.     /**
  348.      * return the time in second the contact is idle.
  349.      */
  350.     unsigned long int idleTime() const;
  351.  
  352.     /**
  353.      * Return a XML representation of the metacontact
  354.      * @internal
  355.      * @param minimal When true, it doesn't save the
  356.      * plugins, groups and notification data. False by default.
  357.      */
  358.     const QDomElement toXML(bool minimal = false);
  359.  
  360.     /**
  361.      * Creates a metacontact from XML
  362.      * Return value of false indicated that
  363.      * creation failed and this contact should be
  364.      * discarded.
  365.      * @internal
  366.      */
  367.     bool fromXML( const QDomElement& cnode );
  368.  
  369.     /**
  370.      * Get or set a field for the KDE address book backend. Fields not
  371.      * registered during the call to Plugin::addressBookFields()
  372.      * cannot be altered!
  373.      *
  374.      * @param p The Plugin by which uses this field
  375.      * @param app refers to the application id in the libkabc database.
  376.      * This should be a standardized format to make sense in the address
  377.      * book in the first place - if you could use "" as application
  378.      * then probably you should use the plugin data API instead of the
  379.      * address book fields.
  380.      * @param key The name of the address book field to get or set
  381.      *
  382.      * @todo: In the code the requirement that fields are registered first
  383.      *        is already lifted, but the API needs some review before we
  384.      *        can remove it here too.
  385.      *        Probably it requires once more some rewrites to get it working
  386.      *        properly :( - Martijn
  387.      */
  388.     QString addressBookField( Plugin *p, const QString &app, const QString &key ) const;
  389.  
  390.     /**
  391.      * @brief set an address book field
  392.      *
  393.      * @see also @ref addressBookField()
  394.      * @param p The Plugin by which uses this field
  395.      * @param app The application ID in the KABC database
  396.      * @param key The name of the address book field to set
  397.      * @param value The value of the address book field to set
  398.      */
  399.     void setAddressBookField( Plugin *p, const QString &app, const QString &key, const QString &value );
  400.  
  401. public slots:
  402.  
  403.     /**
  404.      * @brief Send a file to this metacontact
  405.      *
  406.      * This is the MetaContact level slot for sending files. It may be called through the
  407.      * "Send File" entry in the GUI, or over DCOP. If the function is called through the GUI,
  408.      * no parameters are sent and they assume default values. This slot calls the slotSendFile
  409.      * with identical params of the highest ranked contact capable of sending files (if any)
  410.      *
  411.      * @param sourceURL The actual KURL of the file you are sending
  412.      * @param altFileName (Optional) An alternate name for the file - what the receiver will see
  413.      * @param fileSize (Optional) Size of the file being sent. Used when sending a nondeterminate
  414.      *                file size (such as over a socket)
  415.      *
  416.      */
  417.     void sendFile( const KURL &sourceURL, const QString &altFileName = QString::null,
  418.         unsigned long fileSize = 0L );
  419. signals:
  420.     /**
  421.      * This metaContact is going to be saved to the contactlist. Plugins should
  422.      * connect to this signal to update data with setPluginData()
  423.      */
  424.     void aboutToSave( Kopete::MetaContact *metaContact );
  425.  
  426.     /**
  427.      * One of the subcontacts' idle status has changed.  As with online status,
  428.      * this can occur without the metacontact changing idle state
  429.      */
  430.     void contactIdleStateChanged( Kopete::Contact *contact );
  431.  
  432.  
  433. public slots:
  434.  
  435.     /**
  436.      * @brief Move a contact from one group to another.
  437.      */
  438.     void moveToGroup( Kopete::Group *from, Kopete::Group *to );
  439.  
  440.     /**
  441.      * @brief Remove a contact from one group
  442.      */
  443.     void removeFromGroup( Kopete::Group *from );
  444.  
  445.     /**
  446.      * @brief Add a contact to another group.
  447.      */
  448.     void addToGroup( Kopete::Group *to );
  449.  
  450.     /**
  451.      * @brief Set if this is a temporary contact. (see @ref isTemporary)
  452.      *
  453.      * @param b if the contact is or not temporary
  454.      * @param group if the contact was temporary and b is false, then the contact will be moved to this group.
  455.      *  if group is null, it will be moved to top-level
  456.      */
  457.     void setTemporary( bool b = true, Kopete::Group *group = 0L );
  458.  
  459.     /**
  460.      * @brief Contact another user.
  461.      *
  462.      * Depending on the config settings, call sendMessage() or
  463.      * startChat()
  464.      *
  465.      * returns the Contact that was chosen as the preferred
  466.      */
  467.     Contact *execute();
  468.  
  469.     /**
  470.      * @brief Send a single message, classic ICQ style.
  471.      *
  472.      * The actual sending is done by the Contact, but the meta contact
  473.      * does the GUI side of things.
  474.      * This is a slot to allow being called easily from e.g. a GUI.
  475.      *
  476.      * returns the Contact that was chosen as the preferred
  477.      */
  478.     Contact *sendMessage();
  479.  
  480.     /**
  481.      * @brief Start a chat in a persistent chat window
  482.      *
  483.      * Like sendMessage, but this time a full-blown chat will be opened.
  484.      * Most protocols can't distinguish between the two and are either
  485.      * completely session based like MSN or completely message based like
  486.      * ICQ the only true difference is the GUI shown to the user.
  487.      *
  488.      * returns the Contact that was chosen as the preferred
  489.      */
  490.     Contact *startChat();
  491.  
  492. signals:
  493.     /**
  494.      *  @brief The MetaContact online status changed
  495.      */
  496.     void onlineStatusChanged( Kopete::MetaContact *contact, Kopete::OnlineStatus::StatusType status );
  497.  
  498.     /**
  499.      * @brief A contact's online status changed
  500.      *
  501.      * this signal differs from @ref onlineStatusChanged because a contact can
  502.      * change his status without changing MetaContact status. It is mainly used to update the small icons
  503.      * in the contactlist
  504.      */
  505.     void contactStatusChanged( Kopete::Contact *contact, const Kopete::OnlineStatus &status );
  506.  
  507.     /**
  508.      * @brief The meta contact's display name changed
  509.      */
  510.     void displayNameChanged( const QString &oldName, const QString &newName );
  511.  
  512.     /**
  513.      * @brief The meta contact's photo changed
  514.      */
  515.     void photoChanged();
  516.  
  517.     /**
  518.      * @brief  The contact was moved
  519.      */
  520.     void movedToGroup( Kopete::MetaContact *contact, Kopete::Group *from, Kopete::Group *to );
  521.  
  522.     /**
  523.      * @brief The contact was removed from group
  524.      */
  525.     void removedFromGroup( Kopete::MetaContact *contact, Kopete::Group *group );
  526.  
  527.     /**
  528.      * @brief The contact was added to another group
  529.      */
  530.     void addedToGroup( Kopete::MetaContact *contact, Kopete::Group *to );
  531.  
  532.     /**
  533.      * @brief a contact has been added into this metacontact
  534.      *
  535.      * This signal is emitted when a contact is added to this metacontact
  536.      */
  537.     void contactAdded( Kopete::Contact *c );
  538.  
  539.     /**
  540.      * @brief a contact has been removed from this metacontact
  541.      *
  542.      * This signal is emitted when a contact is removed from this metacontact
  543.      */
  544.     void contactRemoved( Kopete::Contact *c );
  545.  
  546.     /**
  547.      * Some part of this object's persistent data (as returned by toXML) has changed.
  548.      */
  549.     void persistentDataChanged(  );
  550.  
  551. private slots:
  552.     /**
  553.      * Update the contact's online status and emit onlineStatusChanged
  554.      * when appropriate
  555.      */
  556.     void updateOnlineStatus();
  557.  
  558.     /**
  559.      * One of the child contact's online status changed
  560.      */
  561.     void slotContactStatusChanged( Kopete::Contact *c, const Kopete::OnlineStatus &status, const Kopete::OnlineStatus &oldStatus );
  562.  
  563.     /**
  564.      * One of the child contact's property changed
  565.      */
  566.     void slotPropertyChanged( Kopete::Contact *contact, const QString &key, const QVariant &oldValue, const QVariant &newValue  );
  567.  
  568.     /**
  569.      * A child contact was deleted, remove it from the list, if it's still
  570.      * there
  571.      */
  572.     void slotContactDestroyed( Kopete::Contact* );
  573.  
  574.     /**
  575.      * If a plugin is loaded, maybe data about this plugin are already cached in the metacontact
  576.      */
  577.     void slotPluginLoaded( Kopete::Plugin *plugin );
  578.  
  579.     /**
  580.      * When all the plugins are loaded, set the Contact Source.
  581.      */
  582.     void slotAllPluginsLoaded();
  583.  
  584.     /**
  585.      * Update the KABC Picture when the addressbook is changed.
  586.      */
  587.     void slotUpdateAddressBookPicture();
  588.  
  589. protected:
  590.     //QImage photoFromContact( Kopete::Contact *c) const;
  591.     //QImage photoFromKABC( const QString &id ) const;
  592.     QImage photoFromCustom() const;
  593.     //QString nameFromContact( Kopete::Contact *c) const;
  594.     //QString nameFromKABC( const QString &id ) const;
  595.  
  596.     QString sourceToString(PropertySource source) const;
  597.     PropertySource stringToSource(const QString &name) const;
  598. private:
  599.     class Private;
  600.     Private *d;
  601. };
  602.  
  603. // util functions shared with metacontact property dialog
  604. KOPETE_EXPORT QImage photoFromContact( Kopete::Contact *c) /*const*/;
  605. KOPETE_EXPORT QImage photoFromKABC( const QString &id ) /*const*/;
  606. KOPETE_EXPORT QString nameFromContact( Kopete::Contact *c) /*const*/;
  607. KOPETE_EXPORT QString nameFromKABC( const QString &id ) /*const*/;
  608.  
  609. } //END namespace Kopete
  610.  
  611.  
  612. #endif
  613.  
  614. // vim: set noet ts=4 sts=4 sw=4:
  615.  
  616.